<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>每日推荐</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/css/oksub.css}">
    <link rel="stylesheet" th:href="@{/lib/iview/styles/iview.css}">
</head>
<body>
<div id="app" class="ok-body" v-cloak>
    <!--模糊搜索区域-->
    <template>
        <div style="margin-bottom: 8px;margin-top: 8px;">
            <i-input placeholder="输入内容"  v-model="image.description"  style="width: 200px"></i-input>
            <i-button type="primary"  icon="ios-search" @click="load()">搜索</i-button>
            <i-button type="primary"  icon="ios-redo" @click="reload()" >重置</i-button>
            <i-button type="primary" icon="ios-hammer" @click="removeAll(1)" >恢复</i-button>
            <i-button type="primary" icon="md-trash" @click="removeAll(0)" >删除</i-button>
            <i-button type="primary" style="float:right" icon="md-add" @click="add()" >新增</i-button>
        </div>
    </template>
    <template>
        <i-table size="small" :columns="tableTitle"  :data="tableData">
        </i-table>
        <br>
        <Page  style="float: right;" :current="image.pageNumber" :total="tableSize" :page-size="image.pageSize"  @on-change="changePage" @on-page-size-change="changePageSize" show-elevator show-sizer show-total></Page>
    </template>
</div>
<!--js逻辑-->
<script type="text/javascript" th:src="@{/lib/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/lib/vue/vue.min.js}" ></script>
<script type="text/javascript" th:src="@{/lib/iview/iview.min.js}"></script>
<script th:inline="none">
layui.use(["okUtils", "okLayer"], function () {
    var okUtils = layui.okUtils;
    var okLayer = layui.okLayer;
    var vm = new Vue({
        el: '#app',
        data: function(){
        var _this = this;
		return {
            tableTitle : [{
                title: '序号',
                minWidth : 100,
                render: function(h, params) {
                    return h('span', params.index + (_this.image.pageNumber- 1) * _this.image.pageSize + 1);
                }
            },{
                key : "title",
                title : "标题",
                minWidth:300
            },{
                key : "gmtCreate",
                title : "创建时间",
                minWidth:150
            },{
                key : "status",
                title : "状态",
                minWidth:100,
                render : function(h, params) {
                    var status = params.row.status==0?"删除":"正常";
                    return h('div', status);
                }
            },{
                key : "hot",
                title : "推荐",
                minWidth:100,
                render : function(h, params) {
                    var status = params.row.hot==0?"否":"是";
                    return h('div', status);
                }
            },{
                title : '操作',
                key : 'action',
                minWidth : 450,
                align : 'center',
                render : function(h, params) {
                    var functionList = [];
                    var edit = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'md-create'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.edit(params.row);
                            }
                        }
                    }, '修改');
                    functionList.push(edit);
                    var remove = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'md-trash'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.remove(params.row);
                            }
                        }
                    }, '删除');
                    functionList.push(remove);
                    var push = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'ios-jet'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.push(params.row);
                            }
                        }
                    }, '推送');
                    functionList.push(push);
                    var hot = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'ios-jet'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.hot(params.row);
                            }
                        }
                    }, '推荐');
                    functionList.push(hot);
                    var copy = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'md-copy'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.copy(params.row);
                            }
                        }
                    }, '复制');
                    functionList.push(copy);
                    return h('div', functionList);
                }
            } ],
            tableData : [],
            image  : {
                pageSize : 10,
                pageNumber : 1,
                description:'',
            },
            tableSize : 50,
          }
        },
        methods: {
            load : function() {
               var _this = this;
               okUtils.ajax("/sys/recommend/list", "post", this.image, false).done(function (response) {
                    _this.tableData = response.msg.pageData;
                    _this.tableSize = response.msg.totalCount;
                }).fail(function (error) {
                    console.log(error)
                });
            },
            reload : function(){
                this.image.pageNumber=1;
                this.image.pageSize=10;
                this.image.pornStatus=null;
                this.load();
            },
            changePage : function(pageNumber) {
                vm.image.pageNumber = pageNumber;
                vm.load();
            },
            changePageSize : function(pageSize) {
                vm.image.pageSize = pageSize;
                vm.load();
            },
            edit : function(image) {
               okUtils.dialogOpen({
                    title: '修改',
                    id:"images",
                    url: "weChat/recommend/form.html",
                    scroll : true,
                    width: '95%',
                    height: '95%',
                    success : function(dialog) {
                        dialog.vm.recommend = JSON.parse(JSON.stringify(image));
                        dialog.vm.load();
                    },
                    yes : function(dialog) {
                        dialog.vm.acceptClick(vm);
                    }
                });
            },
            remove : function(image) {
                okLayer.confirm("确定要删除吗？", function () {
                    okUtils.ajaxCloud({
                        url:"/sys/recommend/delete",
                        param : {id:image.id},
                        success : function(result) {
                            okLayer.msg.greenTick(result.msg, function () {
                                  vm.load();
                            })
                        }
                    });
                 })
            },
            add: function(image) {
                 okUtils.dialogOpen({
                    title: '新增',
                    url: "weChat/recommend/form.html",
                    scroll : true,
                    width: '95%',
                    height: '95%',
                    success : function(dialog) {

                    },
                    yes : function(dialog) {
                        dialog.vm.acceptClick(vm);
                    }
                });
            },
            push:function(image){
                okLayer.confirm("确定要推送吗？", function () {
                    okUtils.ajaxCloud({
                        url:"/sys/push/today",
                        param : {id:image.id},
                        success : function(result) {
                            okLayer.msg.greenTick(result.msg, function () {
                                  vm.load();
                            })
                        }
                    });
                 })
            },
            hot:function(image){
                okLayer.confirm("确定要设置为今日推荐吗？", function () {
                    okUtils.ajaxCloud({
                        url:"/sys/recommend/hot",
                        param : {id:image.id},
                        success : function(result) {
                            okLayer.msg.greenTick(result.msg, function () {
                                  vm.load();
                            })
                        }
                    });
                 })
            },
            removeAll:function(status){
                okLayer.confirm("确定要执行此操作吗？", function () {
                    okUtils.ajaxCloud({
                        url:"/sys/recommend/removeAll",
                        param : {status:status},
                        success : function(result) {
                            okLayer.msg.greenTick(result.msg, function () {
                                  vm.load();
                            })
                        }
                    });
                 })
            },
            copy:function(image){
                var url = "pages/detail/detail?uuid="+image.uuid+"&title="+image.title;
                okLayer.confirm(url, function () {

                })
            }
        },
        created: function() {
            this.load()
        }
    })
  });
</script>
</body>
</html>
